/*
 * Created on Jan 25, 2009
 */
package ro.letsdoitromania;

import javax.microedition.lcdui.Display;
import com.mgmaps.app.APPSettings;

public class SerialCall implements Runnable {

  public static final int SC_ALERT = 1;  
  
  public static final SerialCall instance = new SerialCall();
  
  private int type;
  private String title;
  private String msg;
  private volatile boolean inSerialCall;
  
  private SerialCall() {
  }
  
  public void show(int typ, String t, String m) {
    this.title = t;
    this.msg = m;
    show(typ);
  }
  
  public void show(int t) {
    // ignore any calls while in another serial call
    if (inSerialCall)
      return;
    
    this.type = t;
    inSerialCall = true;
    Display.getDisplay(LDIRMidlet.instance).callSerially(this);
  }
  
  public void run() {
    switch(type) {
      case SC_ALERT:
        LDIRCanvas.instance.showAlert(title, msg, APPSettings.alertTimeout);
        break;
    }
    inSerialCall = false;
  }

}
